package com.yunhoo.contract.bean;

import com.yunhoo.contract.db.impl.ContractAlertImpl;
import com.yunhoo.contract.model.PayInformation;
import java.io.Serializable;
import java.util.Calendar;
import java.util.Date;
import java.util.List;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;

@ManagedBean(name = "contractAlertBean")
@SessionScoped
public class ContractAlertBean implements Serializable {

    private List<PayInformation> dataList = null;
    private Integer days = 30;
    private Double totalAmount;

    public ContractAlertBean() {
        initList();
    }

    public void queryli() {
        initList();
    }

    private void initList() {
        Calendar calendar = Calendar.getInstance();
        calendar.add(Calendar.DAY_OF_MONTH, days);
        Date alertDate = calendar.getTime();

        dataList = ContractAlertImpl.queryAlertList(alertDate);

        if (dataList == null) return;
        
        initTotalAmount();
    }

    private void initTotalAmount() {
        Double temp = 0d;
        for (PayInformation row : dataList) {
            temp += row.getMoney();
        }
        totalAmount = temp;
    }

    public List<PayInformation> getDataList() {
        return dataList;
    }

    public void setDataList(List<PayInformation> dataList) {
        this.dataList = dataList;
    }

    public Integer getDays() {
        return days;
    }

    public void setDays(Integer days) {
        this.days = days;
    }

    public Double getTotalAmount() {
        return totalAmount;
    }

    public void setTotalAmount(Double totalAmount) {
        this.totalAmount = totalAmount;
    }
}
